<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.bootcss.com/vue/2.6.11/vue.min.js"></script>
</head>
<body>
    <div id="app">
        id: <input type="text" v-model="id"> 
        name: <input type="text" v-model="name">
        <button @click="add">add</button>

        <!-- 
            每次 list 属性发生变化的时候， 都会引起这个v-for循环重新执行一遍 
            我的问题是，当我修改id属性的时候，v-for循环会不会重新执行一遍， 会！！
        -->
        <div v-for="item in getList()" :key="item.id">
            <input type="checkbox"> {{item.id}} - {{item.name}}
        </div>
    </div>    

    <script>
        var app = new Vue({
            el: "#app",
            data: {
                id: null,
                name: null,
                list: [
                    {id: 1, name: '关羽'},
                    {id: 2, name: '张飞'},
                    {id: 3, name: '赵云'},
                    {id: 4, name: '马超'},
                    {id: 5, name: '黄忠'},
                ]
            },
            methods: {
                add() {
                    // 向集合末尾添加元素
                    // this.list.push({"id":this.id, "name":this.name});    

                    // 向集合开头添加元素
                    this.list.unshift({"id":this.id, "name":this.name});    

                    this.id = this.name = '';                
                },
                getList() {
                    console.log("getList执行了...");
                    return this.list;
                }
            }
        });
    </script>
</body>
</html>